package com.gem.eolane.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gem.eolane.entity.Demo;
import com.gem.eolane.entity.PcbOffer;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface BackstaMapper extends BaseMapper<PcbOffer> {

    //历史订单详情
    @Select("select * from Pcb_Offer where id= #{id} ORDER BY 'id' DESC")
    List<PcbOffer> findPcbList(String id);

    //批量删除
   @Update({
           "<script>"
           +"update pcb_offer set del_Ident=1 where id in"
           +"<foreach collection='list' item='id' open='(' separator=',' close=')'>"
           +"#{id}"
           +"</foreach>"
           +"</script>"
   })
    void listdelreues(List<Integer> list);

   //根据订单编号查询
    @Select("SELECT p.id,u.id,u.user_name,u.company,o.type,o.order_number,p.create_time,p.price2 FROM pcb_offer p , user u ,orders o where p.id =o.order_id and o.user_id=u.id and p.del_ident=0 and o.order_number like '%${value}%' and p.del_ident=0 order by o.id desc")
    List<Demo> findbyoid(String IdCard);



    //根據公司名稱查詢
    @Select("SELECT p.id,u.id,u.user_name,u.company,o.type,o.order_number,p.create_time,p.price2 FROM pcb_offer p , user u ,orders o where p.id =o.order_id and o.user_id=u.id and u.company like '%${company}%' and p.del_ident=0 order by o.id desc limit #{CURRENT_PAGE},#{PAGE_SIZE}")
     List<Demo> findComp(String company, Integer CURRENT_PAGE, Integer PAGE_SIZE);

    //查询总数返回pcb订单页面
    @Select("select count(*) from pcb_offer where user_id in (select id from user where company like '%${value}%') and del_ident=0")
     int Comcount(String company);

    //3表关联查询数据返回历史订单页面
    @Select("SELECT p.id,u.id,u.user_name,u.company,o.type,o.order_number,p.create_time,p.price2 FROM pcb_offer p , user u ,orders o where p.id =o.order_id and o.user_id=u.id and p.del_ident=0 order by o.id desc limit #{CURRENT_PAGE},#{PAGE_SIZE}")
     List<Demo> listro(Integer CURRENT_PAGE, Integer PAGE_SIZE);

    //查询历史订单总数
    @Select("select count(*) from pcb_offer where del_ident=0")
     int listroCount();

    //3表关联查询数据返回pcb订单页面
    @Select("SELECT p.id,u.id,u.user_name,u.company,p.del_ident,o.type,o.order_number,p.create_time,p.price2 FROM pcb_offer p , user u ,orders o where p.id =o.order_id and o.user_id=u.id and p.del_ident=0 order by o.id desc limit #{CURRENT_PAGE},#{PAGE_SIZE}")
    List<Demo> demo(Integer CURRENT_PAGE, Integer PAGE_SIZE);

    //查询总数返回pcb订单页面
    @Select("select count(*) from pcb_offer where del_ident=0")
     int count();


}
